package me.zingon.wxbus.controller;

import me.zingon.wxbus.model.Line;
import me.zingon.wxbus.model.Station;
import me.zingon.wxbus.service.LineService;
import me.zingon.wxbus.service.StationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/station")
public class StationController {

    @Autowired
    StationService stationService;

    @Autowired
    LineService lineService;

    @GetMapping("/test")
    public void test(){
        stationService.exc();
    }


    @GetMapping("/list")
    public Object getF(String name){
        Line line = lineService.getByName(name);
        List<Station> stations=stationService.listByLine(line);
        List<String> busName = stationService.listBusNameByLine(line);
        return busName;
    }

    @GetMapping("/names")
    public Object listNames(String name){
        Line line = lineService.getByName(name);
        List<Station> stations=stationService.listByLine(line);
        return stations.stream().map(station -> station.getStationName()).collect(Collectors.toList());
    }

    @GetMapping("/busnames")
    public Object listBusNames(String name){
        Line line = lineService.getByName(name);
        List<String> busName = stationService.listBusNameByLine(line);
        List<String> result=new ArrayList<>();
        busName.stream().forEach(n->{
            result.add(n+"第 1 趟");
            result.add(n+"第 2 趟");
            result.add(n+"第 3 趟");
            result.add(n+"第 4 趟");
            result.add(n+"第 5 趟");
            result.add(n+"第 6 趟");
        });
        return busName;
    }

    @GetMapping("/a")
    public Object a(String name){
        Line line = lineService.getByName(name);
        return stationService.listSeries(line);
    }


}
